package com.foxzzz.array;


import com.foxzzz.base.ArrayUtil;

public class Solution238 {
    public int[] productExceptSelf(int[] nums) {
        int[] answer = new int[nums.length];
        int right = 1;
        answer[0] = 1;
        for (int i = 1; i < nums.length; i++) {
            answer[i] = answer[i - 1] * nums[i - 1];
        }
        for (int i = nums.length - 2; i >= 0; i--) {
            right = right * nums[i + 1];
            answer[i]=answer[i]*right;

        }
        return answer;
    }

    public static void main(String[] args) {
        int[] generator = ArrayUtil.generator(1, 2, 3, 4);
        ArrayUtil.visit(new Solution238().productExceptSelf(generator));
    }
}
